<?php
// 获取当前有效token脚本
require_once __DIR__ . '/vendor/autoload.php';

// 手动加载Laravel配置
$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

use Illuminate\Support\Facades\DB;

echo "获取用户ID为1的当前有效token:\n\n";

try {
    $tokenRecord = DB::table('mini_tokens')
        ->where('user_id', 1)
        ->where('expired_time', '>', now())
        ->orderBy('created_at', 'desc')
        ->first();
    
    if ($tokenRecord) {
        echo "找到有效token:\n";
        echo "Token: {$tokenRecord->token}\n";
        echo "过期时间: {$tokenRecord->expired_time}\n";
        echo "创建时间: {$tokenRecord->created_at}\n\n";
        
        echo "用于curl测试的完整命令:\n";
        echo "curl \"https://nzy-api.congqian.cn/Api/MiniProgram/updateUserInfo\" \\\n";
        echo "  -H \"authorization: Bearer {$tokenRecord->token}\" \\\n";
        echo "  -H \"content-type: application/json\" \\\n";
        echo "  -d '{\"nickname\":\"测试昵称\",\"avatar\":\"\"}'\n";
        
    } else {
        echo "没有找到有效的token记录\n";
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
}